/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.magallanes.ide.action;

import com.rw.magallanes.core.Category;
import com.rw.magallanes.core.Item;
import com.rw.magallanes.core.Warehouse;
import com.rw.magallanes.ide.main.MainFrame;
import com.rw.magallanes.ide.main.MainSystem;
import com.rw.magallanes.utilities.MessageType;
import com.rw.magallanes.utilities.Utilities;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author Gonzalez
 */
public class ChangeCategoryAction extends AbstractAction {

    @Override
    public void actionPerformed(ActionEvent e) {
        MainSystem ms = MainSystem.getInstance();
        MainFrame mf = ms.getMainFrame();
        Warehouse wh = mf.getWarehouse();

        Item item = mf.getSelectedItem();
        Category oldCategory = item.getCategory();
        Category[] categoriesArray = wh.getCategoriesArray();
        String ttl = "Cambiar Categoria";
        String msg = "Categoria";
        int type = JOptionPane.PLAIN_MESSAGE;
        Category category = (Category) JOptionPane.showInputDialog(mf, msg, ttl, type, null, categoriesArray, categoriesArray[0]);

        if (category != null) {
            oldCategory.deleteItem(item);
            category.addItem(item);
            item.setCategory(category);

            mf.updateItemsFor(oldCategory);
        }

    }

    @Override
    public Object getValue(String key) {
        if (key.compareTo(NAME) == 0) {
            return "Cambiar Categoria";
        } else {
            return super.getValue(key);
        }
    }
}
